#include "stdafx.h"
#include "HistoryIndicatorMain.h"
#include "DataManager.hpp"
#include "HistoryIndicator.h"
#include "HistoryGlobal.h"
#include "DebugAssist.h"
#include "HistoryView.h"
#include "KLineMain.h"

CHistoryIndicatorMain::CHistoryIndicatorMain(SGHandle owner_handle) : CHistoryIndicatorBase(owner_handle)
{
}

BOOL CHistoryIndicatorMain::OnSGGoodsChange( SGGoodsChange* goods_change_param )
{
	CPeriodType period(goods_change_param->period_type, goods_change_param->period_param);
	CHistoryData::Key key(goods_change_param->goods, period);

	if(m_pData && key == m_pData->m_tKey) {
		return FALSE;
	}

	m_pData = CDataManager<CHistoryData>::Instance()->GetData(key);

	return FALSE;
}

BOOL CHistoryIndicatorMain::OnSGDrawBack( SGCanvas* canvas_param )
{
	CHistoryIndicator* indicator_ptr = (CHistoryIndicator*)owner_handle_;
	int indicator_type = indicator_ptr->GetView()->GetType();
	if(indicator_type != SGIndicator::SG_INDICATOR_MAIN && indicator_type != SGIndicator::SG_INDICATOR_GOODS) {
		return FALSE;
	}

	CKLineMain kline;
	CAxes& axes = indicator_ptr->GetAxes();

	kline.SetType(SGIndicator::SG_MAIN_CANDLE);
	kline.SetData(m_pData);
	kline.Draw(axes, canvas_param);

	return FALSE;
}

BOOL CHistoryIndicatorMain::OnSGDrawFore( SGCanvas* canvas_param )
{
	CHistoryIndicator* indicator_ptr = (CHistoryIndicator*)owner_handle_;
	int indicator_type = indicator_ptr->GetView()->GetType();
	if(indicator_type != SGIndicator::SG_INDICATOR_MAIN && indicator_type != SGIndicator::SG_INDICATOR_GOODS) {
		return FALSE;
	}

	return FALSE;
}